<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="umsroot.css">
<TITLE>
Interrupts
</TITLE>
</HEAD>
<BODY >
<A HREF="umsroot072.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot070.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc181">13.3</A>&nbsp;&nbsp;Interrupts</H2><UL>
<LI><A HREF="umsroot073.html#toc110">Interrupt Identifiers</A>
<LI><A HREF="umsroot073.html#toc111">Asynchronous handling</A>
</UL>

<A NAME="sectinterrupts"></A>
<A NAME="@default739"></A>
Operating systems such as Unix provide a notion of asynchronous interrupts
or signals. In a standalone ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> system, the signals can be handled by
defining interrupt handlers for them. In fact, a set of
default handlers is already predefined in this case.<BR>
<BR>
In an embedded ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP>, signals are usually handled by the host
application, and it is recommended to use the event mechanism described above
(the ec_post_event() library function) to communicate between the host
application and the ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> code.
However, even in this setting, ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> can also handle signals directly,
provided the programmer sets up a corresponding interrupt handler.<BR>
<BR>
<A NAME="toc110"></A>
<H3 CLASS="subsection"><A NAME="htoc182">13.3.1</A>&nbsp;&nbsp;Interrupt Identifiers</H3>
Interrupts are identified either by their signal number (Unix) or
by a name which is derived from the name the signal has in the operating
system. Most built-ins understand both identifiers. It is usually
more portable to use the symbolic name.
The built-in <A HREF="../bips/kernel/event/current_interrupt-2.html"><B>current_interrupt/2</B></A><A NAME="@default740"></A> is provided to check and/or
generate the valid interrupt numbers and their mnemonic names.<BR>
<BR>
<A NAME="toc111"></A>
<H3 CLASS="subsection"><A NAME="htoc183">13.3.2</A>&nbsp;&nbsp;Asynchronous handling</H3>
When an interrupt happens, the ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> system
calls an interrupt handling routine in a manner very similar to
the case of event handling. The only argument to the handler is
the interrupt number.
Just as event handlers may be user defined, so it is possible to define
interrupt handlers. The goal
<BLOCKQUOTE CLASS="quote">
<PRE CLASS="verbatim">
set_interrupt_handler(N, PredSpec)
</PRE></BLOCKQUOTE>
<A NAME="@default741"></A>
assigns the procedure specified by <I>PredSpec</I> as the interrupt handler for
the interrupt identified by <I>N</I> (a number or a name).
Some interrupts cannot be caught by the user (e.g. the <I>kill</I> signal),
trying to establish a handler for them yields an error message. Note that
<I>PredSpec</I> should be one of the predefined handlers. The use of general
user defined predicates is deprecated because of portability considerations.<BR>
<BR>
To test interrupt handlers, the built-in <A HREF="../bips/kernel/opsys/kill-2.html"><B>kill/2</B></A><A NAME="@default742"></A> may be used to send
a signal to the own process.<BR>
<BR>
The predicate <A HREF="../bips/kernel/event/get_interrupt_handler-3.html"><B>get_interrupt_handler/3</B></A><A NAME="@default743"></A>
may be used to find the
current interrupt handler for an interrupt N, in the same manner as
<B>get_event_handler</B>:
<BLOCKQUOTE CLASS="quote">
<PRE CLASS="verbatim">
get_interrupt_handler(N, PredSpec, HomeModule)
</PRE></BLOCKQUOTE>
An interrupt handler has one optional argument, which is the interrupt
number.
There is no argument corresponding to the error culprit, since
the interrupt has no relation to the currently executed predicate.
A handler may be defined which takes no argument (such
as when the handler is defined for only one interrupt type).
If the handler has one argument, the identifier of the interrupt is passed
to the handler when it is called.<BR>
<BR>
The following is the list of predefined interrupt handlers:
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<B>default/0</B><DD CLASS="dd-description">
<A NAME="@default744"></A><BR>
performs the standard UNIX handling of the specified interrupt (signal).
 Setting this handler is equivalent to calling <I>signal(N, SIG_DFL)</I>
 on the C level.
 Thus e.g. specifying
 <BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
    ?- set_interrupt_handler(int, default/0)
    </PRE></BLOCKQUOTE>
 will exit the ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> system when &and;C is pressed.<BR>
<BR>
<DT CLASS="dt-description"><B>true/0</B><DD CLASS="dd-description">
<A NAME="@default745"></A><BR>
This is equivalent to calling <I>signal(N, SIG_IGN)</I> on the C level,
 ie. the interrupt is ignored.<BR>
<BR>
<DT CLASS="dt-description"><B>throw/1</B><DD CLASS="dd-description">
<A NAME="@default746"></A><BR>
Invoke <I>exit_block/1</I> with the interupt's symbolic name.
<DT CLASS="dt-description"><B>abort/0</B><DD CLASS="dd-description"> 
<A NAME="@default747"></A><BR>
Invoke <I>exit_block(abort)</I>.
<DT CLASS="dt-description"><B>halt/0</B><DD CLASS="dd-description">
<A NAME="@default748"></A><BR>
Terminate the ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> process.
<DT CLASS="dt-description"><B>internal/0</B><DD CLASS="dd-description">
 Used by ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> to implement internal functionality like the
 profiler. This is not intended to be used by the user.
<DT CLASS="dt-description"><B>event/1</B><DD CLASS="dd-description">
<A NAME="@default749"></A><BR>
The signal is handled by posting a (synchronous) event. The event
 name is the symbolic name of the interrupt.
</DL>
Apart from these special cases, all other arguments will
result in the specified predicate to be called when the appropriate
interrupt occurs. This general asynchronous interrupt handling
is not supported on all hardware/platforms,
neither in an embedded ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> (including the
<A NAME="@default750"></A> tkeclipse development environment),
and is therefore deprecated.<BR>
<BR>
<HR>
<A HREF="umsroot072.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot070.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
</BODY>
</HTML>
